package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> list(@ApiParam("护理项目名字") String name,
                                                              @ApiParam(value = "页数",defaultValue = "1") Integer pageNum,
                                                              @ApiParam(value = "每页显示的数据条数",defaultValue = "10")Integer pageSize,
                                                              @ApiParam("状态")Integer status){
        PageResponse<NursingProjectVo> list = nursingProjectService.list(name, pageNum, pageSize, status);
        return ResponseResult.success(list);
    }

    @PostMapping
    @ApiOperation("新增项目")
    public ResponseResult addProject(@RequestBody NursingProjectDto dto){
        nursingProjectService.addProject(dto);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult quaryById(@PathVariable Integer id){
        NursingProjectVo nursingProjectVo = nursingProjectService.quaryById(id);
        return ResponseResult.success(nursingProjectVo);
    }


    @PutMapping
    @ApiOperation("修改项目")
    public ResponseResult update(@RequestBody NursingProjectDto dto){
        nursingProjectService.update(dto);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改项目状态")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除项目")
    public ResponseResult delete(@PathVariable Integer id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation("查询全部数据")
    public ResponseResult getAllProject(){
        List<NursingProjectVo> list = nursingProjectService.getAllproject();
        return ResponseResult.success(list);
    }
}
